package com.ggb.readingtime.controller.user

import com.ggb.readingtime.constants.USER_ID
import com.ggb.readingtime.service.JwtService
import io.swagger.v3.oas.annotations.Operation
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono
import com.ggb.readingtime.model.Result

@RestController
@RequestMapping("/user/user")
class UserController(private val jwtService: JwtService) {

    @GetMapping("/login")
    @Operation(summary = "微信登录")
    fun login():Mono<Result<String>>{
        return Mono.just(Result.success(jwtService.createToken("6666")))
    }

    @GetMapping("/demo")
    @Operation(summary = "测试")
    fun demo():Mono<Result<String>>{
        return Mono.just(Result.success("测试成功"))
    }

    @GetMapping("/getUserId")
    @Operation(summary = "获取userId")
    fun getUserId(exchange: ServerWebExchange):Mono<Result<Int>>{
        val userId = exchange.getAttribute<Int>(USER_ID)?:0
        return Mono.just(Result.success(userId))
    }
}